#ifndef HOMEVIEW_H
#define HOMEVIEW_H

#include <QLabel>
#include <QPushButton>
#include <QListWidget>
#include <QTableWidget>
#include <QBoxLayout>
#include <QPair>

#include <viewinterface.h>

typedef QPair<QString, QDateTime> RecentFile;

class HomeViewTopBannerButton : public QLabel
{
    Q_OBJECT

public:
    HomeViewTopBannerButton(const QPixmap & pixmap, QWidget * parent = 0);
};

class HomeViewTopBannerWidget : public QWidget
{
    Q_OBJECT

public:
    HomeViewTopBannerWidget(const QString & text, QWidget * parent = 0);

private:
    QLabel * m_label;
};

class HomeViewTopBanner : public QWidget
{
    Q_OBJECT

public:
    HomeViewTopBanner(QWidget * parent = 0);
};

class HomeViewAction : public QWidget
{
    Q_OBJECT

public:
    HomeViewAction(QAction * action, QWidget * parent = 0);
    void mousePressEvent(QMouseEvent *);

private:
    QAction * m_action;
};

class HomeViewActionsList : public QWidget
{
    Q_OBJECT

public:
    HomeViewActionsList(QWidget * parent = 0);
    void addActionItem(QAction * action);

private:
    QVBoxLayout * m_layout;
};

class HomeViewRecentModel : public QAbstractTableModel
{
    Q_OBJECT

public:
    HomeViewRecentModel(QObject * parent = 0);

    int rowCount(const QModelIndex &parent) const;
    int columnCount(const QModelIndex &parent) const;
    QVariant data(const QModelIndex &index, int role) const;
    QVariant headerData(int section, Qt::Orientation orientation, int role) const;

    void addRecentFile(const RecentFile & file);
    int recentFilesCount() const;
    RecentFile recentFile(int index) const;

private:
    QList<RecentFile> m_list;
};

class HomeViewRecentTable : public QTableView
{
    Q_OBJECT

public:
    HomeViewRecentTable(QWidget * parent = 0);
    void setModel(QAbstractItemModel *model);

public slots:
    void itemClicked(const QModelIndex & index);

signals:
    void openFile(const QString & path);

//    void addRecentItem(const QString & fileName, const QDateTime lastOpened);
};

class HomeViewSettings : public QObject
{
    Q_OBJECT

public:
    HomeViewSettings(QObject * parent = 0);

    HomeViewRecentModel * recentFilesModel() const;

private:
    HomeViewRecentModel * m_recentFilesModel;
};

class HomeViewWidget : public ViewWidget
{
    Q_OBJECT

public:
    HomeViewWidget(HomeViewSettings * settings, QWidget * parent = 0);
    QString pluginName() const;
    void adjustToolbar(const ToolBarItemList &itemsList) const;
    void paintEvent(QPaintEvent *);

public slots:
    void openFileClicked();

signals:
    void openFile(const QString & path);
    void openDocumentation();

private:
    HomeViewRecentTable * m_recentTable;
    HomeViewSettings * m_settings;
};

class HomeViewPlugin : public QObject,
                       public ViewPluginInterface
{
    Q_OBJECT
    Q_INTERFACES(PluginInterface ViewPluginInterface)

public:
    HomeViewPlugin(QObject * parent = 0);

    QString name()const;
    QString description()const;
    bool loadSettings();
    void saveSettings();
    QString viewName()const;
    ViewWidget::ViewType viewType() const;
    QIcon icon(bool active)const;
    ViewWidget * createView(QWidget * parent = 0)const;
    ToolBarItemList toolBarItems(QObject * parent)const;
    SettingsWidget * settingsWidget(QWidget * parent = 0)const;
    void appEvent(AppEvent *event);

private:
    HomeViewSettings * m_settings;
};

#endif // HOMEVIEW_H
